package com.px.chapter_Dec_1.logistics;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;


public class arrblock {
    public static void main(String[] args) {
        ArrayBlockingQueue<String> arrayBlockingQueue= new ArrayBlockingQueue<>(10);
        Thread thread1=new Thread(()->{
           for (int i=0;i<30;i++){
               try {
                   System.out.println("添加"+i);
                   arrayBlockingQueue.put(String.valueOf(i));
                   Thread.sleep(1000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        Thread thread2=new Thread(()->{
           for (int i=0;i<10;i++){
               try {
                   System.out.println( arrayBlockingQueue.take());

               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }
        });
        thread1.start();
        thread2.start();
    }
}
